$(function () {
    $("#jqGrid").jqGrid({
        url: '../dictDyna/list',
        datatype: "json",
        colModel: [
            {label: 'id', name: 'id', width: 50, key: true},
            {label: '字典组编码', name: 'groupCode', width: 80},
            {label: '字典组名称', name: 'groupName', width: 80},
            {
                label: '类型', name: 'type', width: 80, formatter: function (value, options, row) {
                    if (value == '1') {
                        return 'sql';
                    }
                }
            },
            {
                label: '状态', name: 'status', width: 80, formatter: function (value, options, row) {
                    if (value == '1') {
                        return '<span class="label label-success">正常</span>';
                    } else if (value == '0') {
                        return '<span class="label label-primary">失效</span>';
                    } else {
                        return '';
                    }
                }
            },
            {label: '状态时间', name: 'statusTime', width: 80},
            {
                label: '是否系统数据', name: 'isSys', width: 80, formatter: function (value, options, row) {
                    if (value == '1') {
                        return '是';
                    } else if (value == '0') {
                        return '否';
                    } else {
                        return '';
                    }

                }
            }
        ],
        viewrecords: true,
        height: 800,
        rowNum: 20,
        rowList: [20, 30, 50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth: true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader: {
            root: "page.data",
            page: "page.pageNo",
            total: "page.pageCount",
            records: "page.count"
        },
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        },
        gridComplete: function () {
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
        }
    });
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        isShowCond: false,
        btnText: '查询',
        qryForm: {}
    },
    methods: {
        reset: function () {
            this.qryForm.paramKey = '';
        },
        query: function () {
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {},
                page: 1
            }).trigger("reloadGrid");
        },
        toggle: function () {
            this.isShowCond = !this.isShowCond;

            if (this.isShowCond == true) {
                this.btnText = "隐藏"
            } else if (this.isShowCond == false) {
                this.btnText = "查询"
            }

        },
        create: function (event) {
            location.href = "dictDyna_add.html";
        },
        update: function (event) {
            var id = getSelectedRow();
            if (id == null) {
                return;
            }

            location.href = "dictDyna_add.html?id=" + id;
        },
        del: function (event) {
            var ids = getSelectedRows();
            if (ids == null) {
                return;
            }

            confirm('确定要删除选中的记录？', function () {
                $.ajax({
                    type: "POST",
                    url: "../dictDyna/delete",
                    data: JSON.stringify(ids),
                    success: function (r) {
                        if (r.code == 0) {
                            alert('操作成功', function (index) {
                                $("#jqGrid").trigger("reloadGrid");
                            });
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            });
        }
    }
});
